package 滑动窗口;

import java.util.HashMap;
import java.util.Map;

public class 无重复字符的最大长度 {

    public int lengthOfLongestSubstring(String s) {
        Map<Character, Integer> window = new HashMap<>();
        int left=0;
        int right=0;
        int res=0;
        while (right<s.length()){
            char c = s.charAt(right);
            right++;
            window.put(c,window.getOrDefault(c,0)+1);
            while (window.get(c)>1){
                char c1 = s.charAt(left);
                left++;
                window.put(c1,window.getOrDefault(c1,0)-1);
            }
            res=Math.max(res,right-left);
        }
        return res;
    }
}
